﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ClienteSOAPServices.Dominio;
using NHibernate;

namespace ClienteSOAPServices.Persistencia
{
    public class ClienteDAO : BaseDAO<Cliente, int>
    {
        public Cliente ObtenerClientePorNumeroDocumento(int NroDocumento)
        {
            using (ISession sesion = NHibernateHelper.ObtenerSesion())
            {
                string sentenciaSQL = "select u from Cliente as u where u.NumeroDocumento = :nroDoc";
                IQuery query = sesion.CreateQuery(sentenciaSQL);
                query.SetParameter("nroDoc", NroDocumento);
                IList<Cliente> lista = query.List<Cliente>();

                if (lista.Count == 0)
                {
                    Cliente cli_ = null;
                    return cli_;
                }
                else
                {
                    return lista[0];
                }
                
                
            }
        }
    }
}